package worktest.volitale;
/**
 *  测试volitale
 * @author Administrator
 *
 */
public class RunThread extends Thread{
 
	private  boolean isRunning = true;
	
	private void setRunning(boolean isRunning){
		this.isRunning = isRunning;
	}
	
	public void run(){
		System.out.println("进入run方法..");
		while(isRunning == true){
			//..
		}
		System.out.println("线程停止");//如果isRunning不加volatile  这一句是不会打印的
	}
	
	public static void main(String[] args) throws InterruptedException {
		RunThread rt = new RunThread();
		rt.start();
		Thread.sleep(1000);
		rt.setRunning(false);
		System.out.println("isRunning的值已经被设置了false");
	}
	
	
}
